//
//  ImageViewAndLabelTableViewCell.m
//  UI13_UITableViewCellHomework
//
//  Created by dllo on 16/6/22.
//  Copyright © 2016年 司昌宝. All rights reserved.
//

#import "ImageViewAndLabelTableViewCell.h"
#import "Duanzi.h"
#import "GetHeightTools.h"
@interface ImageViewAndLabelTableViewCell ()

@property (nonatomic,retain)UILabel *duanziLabel;
@property (nonatomic,retain)UIImageView *duanziImageView;

@end


@implementation ImageViewAndLabelTableViewCell
-(void)dealloc{
    [_duanzi release];
    [_duanziLabel release];
    [_duanziImageView release];
    [super dealloc];
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self){
        self.duanziLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.duanziLabel];
        [_duanziLabel release];
        
        self.duanziImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:self.duanziImageView];
        [_duanziImageView release];
    }
    return self;
}

-(void)layoutSubviews{
    [super layoutSubviews];
    
    self.duanziLabel.numberOfLines = 0;
    
    self.duanziLabel.frame = CGRectMake(0, 0, self.frame.size.width, [GetHeightTools heightWith:self.duanzi.digest]);
    self.duanziLabel.backgroundColor = [UIColor greenColor];
    
    
   
    /** !!!图片过大,进入重用池的时候,还未完全在画面中消失的时候被重新修改了属性,crash */
//    self.duanziImageView.frame = CGRectMake(0, [GetHeightTools heightWith:self.duanzi.digest] + 10, self.frame.size.width, [GetHeightTools imageHeightWithImageUrl:self.duanzi.img]);
//    self.duanziImageView.backgroundColor = [UIColor redColor];
    
}

-(void)setDuanzi:(Duanzi *)duanzi{
    if (_duanzi != duanzi) {
        [_duanzi release];
        _duanzi = [duanzi retain];
    }
    
    self.duanziLabel.text = duanzi.digest;
    
    NSURL *url = [NSURL URLWithString:duanzi.img];
    
    NSData *data = [NSData dataWithContentsOfURL:url];
    
    UIImage *image = [UIImage imageWithData:data];
    
    self.duanziImageView.image = image;
    
    
    self.duanziImageView.frame = CGRectMake(0, [GetHeightTools heightWith:self.duanzi.digest] + 10, self.frame.size.width, [GetHeightTools imageHeightWithImageUrl:self.duanzi.img]);
    self.duanziImageView.backgroundColor = [UIColor redColor];
    
}






@end
